package com.example.book.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.example.book.model.Book;
import com.example.book.repository.BookList;

/**
 * Servlet implementation class BookEdit1Servlet
 */
@WebServlet("/edition1")
public class BookEdit1Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		response.setContentType("text/html");
		String isbn= request.getParameter("isbn");
		BookList bl = new BookList();
		Book book = bl.getBook(isbn);
		
		out.println("<html>");
		out.println("<body>");
		out.println("<FORM method='GET' action='/BBStore/edition2'>");
		out.println("<TABLE BORDER=0>");
		out.println("<TR>");
		out.println("<TD>");
		out.println("Title");
		out.println("</TD>");
		out.println("<TD>");
		out.println("<INPUT type=text size='30' name='title' value='"+book.getTitle()+"'>");
		out.println("</TD>");
		out.println("</TR>");
		out.println("<TR>");
		out.println("<TD>");
		out.println("Price");
		out.println("</TD>");
		out.println("<TD>");
		out.println("<INPUT type=text size='30' name='price' value='"+book.getPrice()+"'>");
		out.println("</TD>");
		out.println("</TR>");
		out.println("<TR>");
		out.println("<TD>");
		out.println("Author");
		out.println("</TD>");
		out.println("<TD>");
		out.println("<INPUT type=text size='30' name='author' value='"+book.getAuthor()+"'>");
		out.println("</TD>");
		out.println("</TR>");
		out.println("<TR>");
		out.println("<TD>");
		out.println("</TD>");
		out.println("<TD>");
		out.println("<INPUT type='hidden' name='isbn' value='"+book.getIsbn()+"'>");
		out.println("</TD>");
		out.println("</TR>");
		out.println("<TR>");
		out.println("<TD COLSPAN=2>");
		out.println("<INPUT type='submit' value='Envoyer'>");
		out.println("</TD>");
		out.println("</TR>");
		out.println("</TABLE>");
		out.println("</FORM>");
		out.println("</body>");
		out.println("</html>");		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
